from Components.Component import Component

class ReceiveGlass(Component):

  def __call__(self, values):
      # values['actor_input'] = [{'recv_date': ['2011/05/23'],'vendor': ['BioStar'] }]

      step_legend = ['1. Receive glass from manufacturers',
                     '2. Specify recipe',
                     '3. SRD (Spin/Rinse Dryer) load and unload',
                     '4. H2O DI Resistivity',
                     '5. Q: is it clean']
      
      # the "values" are used to "pre-fill" the input form 
      input_dict = {'recv_date':{'type':'date', 'value':'2111/11/30'}, 
                    'manuf_date':{'type':'date', 'value':'2111/11/30'},
                    'unwrap_date':{'type':'date', 'value':'2111/11/30'},
                    'vendor':{'type':'dropdown', 'value':['BioStar', 'Foobar']}}
      
      # context info for this step [to show user]
      #output_dict = {'field1':'val1', 
      #               'field2':'val2'}
      output_dict = {}
      if 'actor_input' in values:
          for key, value in values['actor_input'][0].items():    # [{u'manuf_date': [u'xxxxxxxxxxxxxx']}]
              output_dict[key] = value
   
   
      # go to next actor in workflow
      if 'actor_input' in values and len(values['actor_input'])>0:
          # debug
          print("\n**** values['actor_input'] in ReceiveGlass.py  ****")
          print(values['actor_input'])

          # put data on the "conveyor belt" to circulate to all actors
          values['r'] = {'step_legend':step_legend, 'output_dict':output_dict, 'input_dict':{}}
          values['r']['next_step'] = 2
          values['status'] = "running"	# possible vaues: 'running', 'awaiting input'
          
          # go to next actor in workflow
          return (([self.get_connection()], values),)

      # loop on self 
      else: 
          print("\n*** ReceiveGlass.py: else clause  ******")
          
          # put data on the "conveyor belt" to circulate to all actors
          # (leave out input_dict)
          values['r'] = {'step_legend':step_legend, 'output_dict':output_dict, 'input_dict':input_dict}
          values['r']['next_step'] = 1
          values['status'] = "awaiting input"	# possible vaues: 'running', 'awaiting input'

          # loop on self until values['square_x'] is received
          return (([self], values),) 